package aos.ydksxt.service.cxfxtj;

import aos.framework.core.typewrap.Dto;
import aos.framework.core.typewrap.Dtos;
import aos.framework.core.utils.AOSJson;
import aos.framework.core.utils.AOSUtils;
import aos.framework.web.router.HttpModel;
import aos.ydksxt.service.common.CommonService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

/**
 * 房管信息查询服务
 * Created by stiofan on 2017/2/2.
 */
@Service
public class FgxxcxfxService extends CommonService {
    @Override
    @Transactional
    public void initView(HttpModel httpModel) {
        httpModel.setViewPath("ydksxt/cxfxtj/fgxxcxfx.jsp");
    }
    @Transactional
    public void queryFgxxcxfxByParams(HttpModel httpModel) {
        String querySql = "select fg.tdzdh,\n" +
                "       fg.fcsyqr,\n" +
                "       fg.jzmj,\n" +
                "       fg.fcyz,\n" +
                "       fg.fcmc,\n" +
                "       fg.fczldz,\n" +
                "       fg.fcqdrq,\n" +
                "       fg.fczsbh,\n" +
                "       fg.fcyt\n" +
                "  from  ydks.dj_wbdr_fgxx fg\n" +
                " where fg.yxbz='Y'\n" ;
        Dto inDto = httpModel.getInDto();
        Dto params = Dtos.newDto();
        if (StringUtils.isNotEmpty(inDto.getString("tdzdh"))) {
            params.put("tdzdh", inDto.getString("tdzdh"));
            querySql += "   and fg.tdzdh = :tdzdh\n" ;
        }
        if (StringUtils.isNotEmpty(inDto.getString("fcsyqr"))) {
            params.put("fcsyqr", inDto.getString("fcsyqr"));
            querySql += "   and fg.fcsyqr = :fcsyqr\n";
        }
        if (StringUtils.isNotEmpty(inDto.getString("fczsbh"))) {
            params.put("fczsbh", inDto.getString("fczsbh"));
            querySql += "   and fg.fczsbh = :fczsbh";
        }
        if (StringUtils.isNotEmpty(inDto.getString("fcmc"))) {
            params.put("fcmc", "%"+ inDto.getString("fcmc")+"%");
            querySql += "   and fg.fcmc like :fcmc";
        }
        if (StringUtils.isNotEmpty(inDto.getString("fcyzq"))) {
            params.put("fcyzq", inDto.getString("fcyzq"));
            querySql += "   and fg.fcyz >= :fcyzq";
        }
        if (StringUtils.isNotEmpty(inDto.getString("fcyzz"))) {
            params.put("fcyzz", inDto.getString("fcyzz"));
            querySql += "   and fg.fcyz <= :fcyzz";
        }
        if (StringUtils.isNotEmpty(inDto.getString("jzmjq"))) {
            params.put("jzmjq", inDto.getString("jzmjq"));
            querySql += "   and fg.jzmj >= :jzmjq";
        }
        if (StringUtils.isNotEmpty(inDto.getString("jzmjz"))) {
            params.put("jzmjz", inDto.getString("jzmjz"));
            querySql += "   and fg.jzmj <= :jzmjz";
        }
        if (StringUtils.isNotEmpty(inDto.getString("fcqdrqq"))) {
            params.put("fcqdrqq", inDto.getDate("fcqdrqq"));
            querySql += "   and fg.fcqdrq >= :fcqdrqq";
        }
        if (StringUtils.isNotEmpty(inDto.getString("fcqdrqz"))) {
            params.put("fcqdrqz", inDto.getDate("fcqdrqz"));
            querySql += "   and fg.fcqdrq <= :fcqdrqz";
        }
        if (StringUtils.isNotEmpty(inDto.getString("fcyt"))) {
            params.put("fcyt", inDto.getString("fcyt"));
            querySql += "   and fg.fcyt = :fcyt";
        }
        List results = persistenceDAO.findAllBySql(querySql, params);
        httpModel.setOutMsg(AOSJson.toGridJson(AOSUtils.list2Map(results)));
    }
}
